// components/head/head.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    userInfo: {
      avatarUrl: defaultAvatarUrl,
      nickName: null,
      openid:'"owgcA7bZec_X8y1SEuN9-wCzuGVI',
     
    },
    hasUserInfo: false,
    canIUseGetUserProfile: wx.canIUse('getUserProfile'),
    canIUseNicknameComp: wx.canIUse('input.type.nickname'),
  },

  /**
   * 组件的方法列表
   */
  methods:{
    onChooseAvatar(e) {
      const { avatarUrl } = e.detail
      const { nickName } = this.data.userInfo
      this.setData({
        "userInfo.avatarUrl": avatarUrl,
        hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
        
      })
       // 更新全局数据
       const app = getApp();
     app.globalData.userInfo.avatarUrl = avatarUrl;
     app.globalData.userInfo.hasUserInfo = true;
    },
      onInputChange(e) {
    const nickName = e.detail.value
    const { avatarUrl } = this.data.userInfo
    this.setData({
      "userInfo.nickName": nickName,
      hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
    })
     // 更新全局数据
     const app = getApp();
        app.globalData.userInfo.nickName = nickName;
        app.globalData.userInfo.hasUserInfo = true;
     
       

  },
  
  },
  attached(){
    const app = getApp();
    if(app.globalData.userInfo.hasUserInfo){
      
this.setData({
          userInfo:{
            avatarUrl: app.globalData.userInfo.avatarUrl,
            nickName:  app.globalData.userInfo.nickName,
            openid:'"owgcA7bZec_X8y1SEuN9-wCzuGVI',
            hasUserInfo:true

          },
         
        })
        console.log("hh")
    }
    
  }
 
})